import {
  Get,
  Controller,
  Post,
  Response,
  Param,
  HttpStatus,
  Request,
  UseGuards,
  Body,
  UsePipes,
  Query,
  Put,
  Req,
} from '@nestjs/common';
import { WxService } from './wx.service';
import { Roles } from '../../auth/roles.decorator';
import { RolesGuard } from '../../auth/roles.guard';
import { PayTest } from './wx.dto';

@Controller('bwx')
export class wxController {
  constructor(private readonly wxService: WxService) {}

  @Post('getClientUserOpenid')
  async getClienUserOpenid(
    @Req() req: Request,
    @Body('code') code: string,
  ): Promise<any> {
    let userInfo = req['userInfo'];
    return await this.wxService.getclientUserOpenid(code, userInfo.userId);
  }

  @Get('/getStsAuto')
  async getStsAuto(@Body() param): Promise<any> {
    return await this.wxService.getStsAuto();
  }

  @Post('/payNotify')
  async payNotify(@Body() body, @Request() req, @Param() param): Promise<any> {
    console.log(body);
    console.log(param);
  }

  @Get('/payNotify')
  async payNotifys(@Query() param, @Body() body, @Request() req): Promise<any> {
    console.log(param);
  }

  @Post('/payRefund')
  async payRefund(@Body() body): Promise<any> {
    return this.wxService.refundTest(
      body.out_trade_no,
      Number(body.total_fee),
      Number(body.refund_fee),
      body.refund_desc,
    );
  }

  @Post('/refundNotify')
  async refundNotify(@Body() body): Promise<any> {
    console.log(body);
  }
  @Get('/geocoder')
  async geocoder(@Query() query): Promise<any> {
    return this.wxService.geocoder(query.lat, query.lng);
  }

  @Get('/validate')
  async validate(@Query('echostr') echostr: string): Promise<string> {
    return echostr;
  }

  /**
   * @description: 公众号网页授权获取openid
   * @return:
   */
  @Get('/getPublicOpenid')
  async getPublicOpenid(@Query('code') code: string): Promise<string> {
    return this.wxService.getPublicOpenid(code);
  }
}
